/**
 *
 */
package com.wedroid.r2d2.support;

import com.wedroid.r2d2.support.response.DroidResponse;

/**
 * @author lute
 */
public class ResponseResult<T extends DroidResponse> {

    private T t;

    private boolean valid;

    private String message;

    /**
     *
     */
    public ResponseResult() {
        this.valid = false;
    }

    /**
     * @return
     */
    public ResponseResult<T> fail() {
        this.valid = false;
        return this;
    }

    /**
     * @param message
     * @return
     */
    public ResponseResult<T> fail(String message) {
        this.message = message;
        return this;
    }

    /**
     * @param t
     * @return
     */
    public ResponseResult<T> response(T t) {
        this.t = t;
        if (t == null || !t.isSuccess()) {
            this.valid = false;
        } else {
            this.valid = true;
        }
        return this;
    }

    /**
     * @return
     */
    public T getValue() {
        return t;
    }

    /**
     * @return the valid
     */
    public boolean isValid() {
        return valid;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

}
